package cn.itcast.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AccountAspect {
    @Around("execution(* cn.itcast.service..*.*(..))")
    public Object around(ProceedingJoinPoint pjp){
        String className = pjp.getSignature().getDeclaringTypeName();
        String methodName = pjp.getSignature().getName();

        try {
            long startTime = System.currentTimeMillis();
            Object result = pjp.proceed(pjp.getArgs());
            long endTime = System.currentTimeMillis();
            System.out.println(className+"."+methodName+" "+"run:"+(endTime-startTime)+"ms");
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    }


}
